package com.goa.utils;

import com.goa.entity.DeviceBase;

/**
 * @author chuyongshuo
 * @version 1.0
 * @date 2024/11/7 9:47
 */
public class ARTUtils {


    /**
     * 电功率
     */
    public static String calculatePower(Integer value, DeviceBase device) {
        if (device==null){
            return "0";
        }
        double w = (float)(value / 65535.0) * (device.getCurrentRange() * device.getVoltageRange() * device.getCurrentRatio()*device.getVoltageRatio()-(-device.getCurrentRange()*device.getVoltageRange())* device.getCurrentRatio()*device.getVoltageRatio())
                +(-device.getCurrentRange()*device.getVoltageRange())* device.getCurrentRatio()*device.getVoltageRatio();
        String power = String.format("%.2f", w);
        return power;
    }

    /**
     * 电度计算
     *
     */
    public static String calculateElect(Integer v1, Integer v2,DeviceBase device) {
        if (device==null){
            return "0";
        }
        String str =v2+v1+"";
        double e = (float)(Long.valueOf(str)-2147483648.0) * device.getCurrentRange() * device.getVoltageRange() * device.getCurrentRatio()*device.getVoltageRatio()/3600/1000;
        String elect = String.format("%.2f", e);
        return elect;
    }

    /**
     * ABC三项电流计算
     */
    public static String calculateCurrent(Integer value, DeviceBase device) {
        double range =0d;
        double ratio =0d;
        if (device!=null){
            range=device.getCurrentRange();
            ratio= device.getCurrentRatio();
        }

        double v = (value / (double) 0xFFFF) * range * ratio;
        String s = String.format("%.2f", v);
        return s;
    }

    /**
     * ABC三项电压/线电压值 计算
     */
    public static String calculateVoltage(Integer value,DeviceBase device) {
        double range =0d;
        double ratio =0d;
        if (device!=null){
            range=device.getVoltageRange();
            ratio=device.getVoltageRatio();
        }
        double v = (value / (double) 0xFFFF) * range * ratio;
        String s = String.format("%.2f", v);
        return s;
    }
}
